package com.doxiaopu.students.product.service.impl;

import com.doxiaopu.students.product.entity.OrganizationSingle;
import com.doxiaopu.students.product.mapper.OrganizationSingleMapper;
import com.doxiaopu.students.product.service.IOrganizationSingleService;
import com.doxiaopu.students.user.entity.User;
import com.doxiaopu.students.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Primary
public class OrganizationSingleServiceImpl implements IOrganizationSingleService {
    @Autowired
    private OrganizationSingleMapper organizationSingleMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public Integer createOrganizationSingle(OrganizationSingle organizationSingle,Integer id) {
        User user = userMapper.getById(id);
        Date now = new Date();
        organizationSingle.setCreatedUser(user.getUsername());
        organizationSingle.setCreatedTime(now);
        organizationSingle.setModifiedUser(user.getUsername());
        organizationSingle.setModifiedTime(now);
        organizationSingle.setTypes(0);
        organizationSingle.setMassOrganizationId(user.getMassOrganizationId());
        return addOrganizationSingle(organizationSingle);
    }

    /**
     * 会长申请返利团单，创建社团与团单的关系表
     * @param organizationSingle
     * @return
     */
    private Integer addOrganizationSingle(OrganizationSingle organizationSingle){
        return organizationSingleMapper.addOrganizationSingle(organizationSingle);
    };
}
